/*
 * @Descripttion:
 * @Author: voanit
 * @Date: 2022-05-16 16:44:44
 * @LastEditors: voanit
 * @LastEditTime: 2022-05-19 11:06:50
 */
import request from '@/utils/request'
import { GET_ARTICLE_LIST } from '@/store/actionTypes'
export const actionArticleList = (params) => {
  return async (dispatch) => {
    // console.log(params, 882222)
    const res = await request({
      url: '/mp/articles',
      params,
    })
    // console.log(res,999111);
    dispatch({ type: GET_ARTICLE_LIST, payload: {articleList:res.data.results,page:1,total_count:res.data.total_count,per_page:res.data.per_page} })
  }
}


export const  actionDelById=(id)=>{
  return async (dispatch)=>{
    await request({
      method: 'delete',
      url: `/mp/articles/${id}`
    })

  }
}
export const  actionPublish=(data,draft=false)=>{
  return async (dispatch)=>{
    await request.post('/mp/articles?draft='+draft, data)
  }
}



export const  actionGetArticleInfo=(id)=>{
  return async () => {
    const res = await request(`/mp/articles/${id}`)
    return res.data
  }
}

export const  actionGetArticleEdit=(data,draft=false)=>{
  return async () => {
    const  res=await request({
      url: `/mp/articles/${data.id}`,
      method: 'put',
      data,
      params: {
        draft
      }
    })
    return res.data
  }
}